<?php

namespace application\controller\cp;

use application\service\IDataService;
use core\system\HttpRequest;
use application\service\CatelogService;

class IDataController extends BaseController {

    private $iDataService;
    private $catelogService;
    public function __construct() {
        parent::__construct();
        
        $this->iDataService = new IDataService();
        $this->catelogService = new CatelogService();
        $this->view->layout = '/layout/main';
    }

    /**
     * Main của module IData
     * @mapping(value=cp/idata.html)
     */
    function grid() {
        $search = HttpRequest::getRequest(\application\entity\input\IDataSearch::class);
        $dataPage = $this->iDataService->search($search);
        $dataCatelog = array();
        foreach ($this->catelogService->getAll()->data as $dataCat) {
            $dataCatelog[$dataCat->id] = $dataCat->name;
        }
        $this->view->dataCatelog = $dataCatelog;
        $this->view->dataPage = $dataPage;
        $this->view->render('/idata/grid');
    }

}
